package com.pms.system.service.impl;

import java.util.List;

import com.pms.common.enums.RoomStatus;
import com.pms.common.utils.DateUtils;
import com.pms.system.domain.vo.PmsGuestroomInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.pms.system.mapper.PmsGuestroomInfoMapper;
import com.pms.system.domain.PmsGuestroomInfo;
import com.pms.system.service.IPmsGuestroomInfoService;

/**
 * 客房信息Service业务层处理
 * 
 * @author 达瓦里氏
 * @date 2023-03-04
 */
@Service
public class PmsGuestroomInfoServiceImpl implements IPmsGuestroomInfoService 
{
    @Autowired
    private PmsGuestroomInfoMapper pmsGuestroomInfoMapper;

    /**
     * 查询客房信息
     * 
     * @param id 客房信息主键
     * @return 客房信息
     */
    @Override
    public PmsGuestroomInfo selectPmsGuestroomInfoById(Long id)
    {
        return pmsGuestroomInfoMapper.selectPmsGuestroomInfoById(id);
    }

    /**
     * 查询客房信息列表
     * 
     * @param pmsGuestroomInfo 客房信息
     * @return 客房信息
     */
    @Override
    public List<PmsGuestroomInfoVo> selectPmsGuestroomInfoList(PmsGuestroomInfo pmsGuestroomInfo)
    {
        return pmsGuestroomInfoMapper.selectPmsGuestroomInfoList(pmsGuestroomInfo);
    }

    /**
     * 新增客房信息
     * 
     * @param pmsGuestroomInfo 客房信息
     * @return 结果
     */
    @Override
    public int insertPmsGuestroomInfo(PmsGuestroomInfo pmsGuestroomInfo)
    {
        pmsGuestroomInfo.setCreateTime(DateUtils.getNowDate());
        // 初始化客房状态为空闲
        pmsGuestroomInfo.setType(RoomStatus.LEISURE.getCode());
        return pmsGuestroomInfoMapper.insertPmsGuestroomInfo(pmsGuestroomInfo);
    }

    /**
     * 修改客房信息
     * 
     * @param pmsGuestroomInfo 客房信息
     * @return 结果
     */
    @Override
    public int updatePmsGuestroomInfo(PmsGuestroomInfo pmsGuestroomInfo)
    {
        pmsGuestroomInfo.setUpdateTime(DateUtils.getNowDate());
        return pmsGuestroomInfoMapper.updatePmsGuestroomInfo(pmsGuestroomInfo);
    }

    /**
     * 批量删除客房信息
     * 
     * @param ids 需要删除的客房信息主键
     * @return 结果
     */
    @Override
    public int deletePmsGuestroomInfoByIds(Long[] ids)
    {
        return pmsGuestroomInfoMapper.deletePmsGuestroomInfoByIds(ids);
    }

    /**
     * 批量删除客房信息
     *
     * @param ids 需要删除的客房信息主键
     * @return 结果
     */
    @Override
    public void housekeeping(Long[] ids)
    {
        for (int i = 0; i < ids.length; i++) {
            PmsGuestroomInfo pmsGuestroomInfo = pmsGuestroomInfoMapper.selectPmsGuestroomInfoById(ids[i]);
            if (!pmsGuestroomInfo.getType().equals("CHECKED_OUT")){
                throw new RuntimeException("无法清理未退房的房间");
            }
            pmsGuestroomInfo.setType(RoomStatus.LEISURE.getCode());
            pmsGuestroomInfoMapper.updatePmsGuestroomInfo(pmsGuestroomInfo);

        }
    }

    /**
     * 删除客房信息信息
     * 
     * @param id 客房信息主键
     * @return 结果
     */
    @Override
    public int deletePmsGuestroomInfoById(Long id)
    {
        return pmsGuestroomInfoMapper.deletePmsGuestroomInfoById(id);
    }
}
